package com.voicesysapp.reactnative;

import android.widget.Toast;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.uimanager.IllegalViewOperationException;
import com.voicesysapp.tripledes.TripleDesUtils;


public class ReactNativeContext extends ReactContextBaseJavaModule {

    public ReactNativeContext(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @Override
    public String getName() {
        return "RNToAndroid";
    }

    /**
     * 提示框
     * @param contest
     */
    @ReactMethod
    public void toastShow(String contest) {
        Toast.makeText(getReactApplicationContext(),contest,Toast.LENGTH_LONG).show();
    }

    /**
     * 解密
     * @param desStr
     * @return
     */
    @ReactMethod
    public void decode3Des(String desStr, Promise promise) {
        try{
            promise.resolve(TripleDesUtils.decode3Des(desStr));
            // promise.resolve("3333333333333333");
        }catch(IllegalViewOperationException e){
            promise.reject("1",e.getMessage());
        }
    }

    /**
     * 加密
     * @param srcStr
     * @return
     */
    @ReactMethod
    public void encode3Des(String srcStr, Promise promise) {
        try{
            promise.resolve(TripleDesUtils.encode3Des(srcStr));
            // promise.resolve("123456");
        }catch(IllegalViewOperationException e){
            promise.reject("1",e.getMessage());
        }
    }
}
